package com.lzx.iteam.adapter;

import android.content.Context;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;
import android.view.ViewGroup;
import com.lzx.iteam.ApprovalFragment;

import java.util.ArrayList;
import java.util.List;

/**
 * Created with IntelliJ IDEA.
 * **********************************
 * User: zhangshuai
 * Date: 2016年 04月 08日
 * Time: 下午3:18
 *
 * @QQ : 1234567890
 * **********************************
 */
public class ApprovalFgAdapter extends FragmentPagerAdapter {

    private Context mContext;
    private List<Fragment> mList;
    private FragmentManager mFm;
    private List<String> tagList = new ArrayList<String>();

    public ApprovalFgAdapter(FragmentManager fm, Context mContext, List<Fragment> mList) {
        super(fm);
        mFm =fm;
        this.mContext = mContext;
        this.mList = mList;
    }

    @Override
    public Fragment getItem(int i) {
        return mList.get(i);
    }

    @Override
    public int getCount() {
        return mList.size();
    }

    @Override
    public Object instantiateItem(ViewGroup container, int position) {
        tagList.add(makeFragmentName(container.getId(), (int) getItemId(position)));
        return super.instantiateItem(container, position);
    }

    @Override
    public void destroyItem(ViewGroup container, int position, Object object) {
        super.destroyItem(container, position, object);
    }

    public static String makeFragmentName(int viewId, int index) {
        return "android:switcher:" + viewId + ":" + index;
    }

    public void update(int item,String groupId) {
        if (tagList.size() >item) {
            Fragment fragment = mFm.findFragmentByTag(tagList.get(item));
            if (fragment != null) {
                switch (item) {
                    case 0:
                        ((ApprovalFragment)fragment).update(groupId);
                        break;
                    case 1:
                        ((ApprovalFragment) fragment).update(groupId);
                        break;
                    default:
                        break;
                }
            }
        }
    }

    /*public interface FragmentListener {
        public void onFragmentClickListener(int item,int position);
    }*/


}
